﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace NAVE_Alice_demo
{
    class HUD
    {
        Texture2D Fundo_HUD1;
        Texture2D Fundo_HUD2;
        Texture2D Fundo_HUD3;
        Texture2D Fundo_HUDFinal;
        Texture2D Relogio;
        Texture2D TexturaSom1;
        Texture2D TexturaSom2;
        Texture2D TexturaSom3;
        Texture2D TexturaSomFinal;
        Texture2D TexturaSair1;
        Texture2D TexturaSair2;
        Texture2D TexturaSair3;
        Texture2D TexturaSairFinal;
        Texture2D vida;

        Vector2 posicao_hud_fundo = new Vector2(600, 0);
        Vector2 posicao_vida = new Vector2(855, 20);
        Vector2 posicao_relogio= new Vector2 (800,8);
        Vector2 posicao_placar = new Vector2(725, 5);
        Vector2 posicao_som = new Vector2(937, 715);
        Vector2 posicao_sair = new Vector2(955, 700);

        SpriteFont Font;
        

        int QuadroSom=41;
        public static int QuadroRelogio = 0;
        int QuadroSair=0;

        bool SairSelecionado = false;
        bool SomSelecionado = false;
        public static bool fechar = false;        
        
        public static bool Mudo=false;

        public static int spriteRelogio = 0;

        

        Texture2D Placar3Dg;

       public void Load(ContentManager Content)
        {
            Fundo_HUD1 = Content.Load<Texture2D>(@"HUD\HUD_Fase1");
            Fundo_HUD2 = Content.Load<Texture2D>(@"HUD\HUD_Fase2");
            Fundo_HUD3 = Content.Load<Texture2D>(@"HUD\HUD_Fase3");
            Fundo_HUDFinal = Content.Load<Texture2D>(@"HUD\HUD_FaseFinal");
            Relogio = Content.Load<Texture2D>(@"HUD\HUD_Tempo");
            TexturaSom1 = Content.Load<Texture2D>(@"HUD\HUD_Fase1_Som");
            TexturaSom2 = Content.Load<Texture2D>(@"HUD\HUD_Fase2_Som");
            TexturaSom3 = Content.Load<Texture2D>(@"HUD\HUD_Fase3_Som");
            TexturaSomFinal = Content.Load<Texture2D>(@"HUD\HUD_FaseFinal_Som");
            TexturaSair1 = Content.Load<Texture2D>(@"HUD\HUD_Fase1_Sair");
            TexturaSair2 = Content.Load<Texture2D>(@"HUD\HUD_Fase2_Sair");
            TexturaSair3 = Content.Load<Texture2D>(@"HUD\HUD_Fase3_Sair");
            TexturaSairFinal = Content.Load<Texture2D>(@"HUD\HUD_FaseFinal_Sair");
            vida = Content.Load<Texture2D>(@"HUD\HUD_Vida");
            Placar3Dg = Content.Load<Texture2D>(@"HUD\HUD_Placar_3digitos");
            Font = Content.Load<SpriteFont>(@"HUD\Font");
       
        }
        public void updateNivel1(GameTime gametime, MouseState mouse_atual, MouseState mouse_anterior)
        {
            ImagemSom(mouse_atual, mouse_anterior);
            ImagemSair(mouse_atual);
            Resultado();
        }

        public void updateNivel2(GameTime gametime, MouseState mouse_atual, MouseState mouse_anterior)
        {
           // posicao_som += Posicao_Tela2;
            ImagemSom(mouse_atual,  mouse_anterior);
            ImagemSair(mouse_atual);
            Resultado();

        }
        public void updateNivel3(GameTime gametime, MouseState mouse_atual, MouseState mouse_anterior)
        {
            ImagemSom(mouse_atual,  mouse_anterior);
            ImagemSair(mouse_atual);
            Resultado();

        }
        public void updateNivelFinal(GameTime gametime, MouseState mouse_atual, MouseState mouse_anterior)
        {
            ImagemSom(mouse_atual,  mouse_anterior);
            ImagemSair(mouse_atual);
            Resultado();
        }


        public SpriteBatch DrawNivel1(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Fundo_HUD1, posicao_hud_fundo, Color.White);
            //spriteBatch.Draw(ObjetoArvore.TexturaImagem, new Rectangle((int)ObjetoArvore.PosicaoImagem.X - (int)Posicao_Tela2.X, (int)ObjetoArvore.PosicaoImagem.Y, ObjetoArvore.TexturaImagem.Width / 3,ObjetoArvore.TexturaImagem.Height), new Rectangle(ObjetoArvore.xQuadro, 0, ObjetoArvore.TexturaImagem.Width / 3, ObjetoArvore.TexturaImagem.Height), Color.White);
            spriteBatch.Draw(TexturaSair1, new Rectangle((int)posicao_sair.X, (int)posicao_sair.Y, TexturaSair1.Width / 2, TexturaSair1.Height), new Rectangle(QuadroSair, 0, TexturaSair1.Width / 2, TexturaSair1.Height), Color.White);
            spriteBatch.Draw(TexturaSom1, new Rectangle((int)posicao_som.X, (int)posicao_som.Y, TexturaSom1.Width / 4, TexturaSom1.Height), new Rectangle(QuadroSom, 0, TexturaSom1.Width / 4, TexturaSom1.Height), Color.White);
            spriteBatch.Draw(Placar3Dg, posicao_placar, Color.White);
            spriteBatch.Draw(Relogio, new Rectangle((int)posicao_relogio.X, (int)posicao_relogio.Y, Relogio.Width / 7, Relogio.Height), new Rectangle(QuadroRelogio, 0, Relogio.Width / 7, Relogio.Height), Color.White);
            spriteBatch.Draw(vida, posicao_vida, Color.White);
            spriteBatch.DrawString(Font, "" + Game1.Vida, new Vector2(890, 20), Color.Black);
            spriteBatch.DrawString(Font, "" + Game1.pontosTotal, new Vector2(745, 20), Color.Black);


            return spriteBatch;
        }

        public SpriteBatch DrawNivel2(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Fundo_HUD2, posicao_hud_fundo, Color.White);
            spriteBatch.Draw(TexturaSair2, new Rectangle((int)posicao_sair.X, (int)posicao_sair.Y, TexturaSair2.Width / 2, TexturaSair2.Height), new Rectangle(QuadroSair, 0, TexturaSair2.Width / 2, TexturaSair2.Height), Color.White);
            spriteBatch.Draw(TexturaSom2, new Rectangle((int)posicao_som.X, (int)posicao_som.Y, TexturaSom2.Width / 4, TexturaSom2.Height), new Rectangle(QuadroSom, 0, TexturaSom2.Width / 4, TexturaSom2.Height), Color.White);
            spriteBatch.Draw(Placar3Dg, posicao_placar, Color.White);
            spriteBatch.Draw(Relogio, new Rectangle((int)posicao_relogio.X, (int)posicao_relogio.Y, Relogio.Width / 7, Relogio.Height), new Rectangle(QuadroRelogio, 0, Relogio.Width / 7, Relogio.Height), Color.White);
            spriteBatch.Draw(vida, posicao_vida, Color.White);
            spriteBatch.DrawString(Font, "" + Game1.Vida, new Vector2(890, 20), Color.Black);
            spriteBatch.DrawString(Font, "" + Game1.pontosTotal, new Vector2(745, 20), Color.Black);

            return spriteBatch;
        }

        public SpriteBatch DrawNivel3(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Fundo_HUD3, posicao_hud_fundo, Color.White);
            spriteBatch.Draw(TexturaSair3, new Rectangle((int)posicao_sair.X, (int)posicao_sair.Y, TexturaSair3.Width / 2, TexturaSair3.Height), new Rectangle(QuadroSair, 0, TexturaSair3.Width / 2, TexturaSair3.Height), Color.White);
            spriteBatch.Draw(TexturaSom3, new Rectangle((int)posicao_som.X, (int)posicao_som.Y, TexturaSom3.Width / 4, TexturaSom3.Height), new Rectangle(QuadroSom, 0, TexturaSom3.Width / 4, TexturaSom3.Height), Color.White);
            spriteBatch.Draw(Placar3Dg, posicao_placar, Color.White);
            spriteBatch.Draw(Relogio, new Rectangle((int)posicao_relogio.X, (int)posicao_relogio.Y, Relogio.Width / 7, Relogio.Height), new Rectangle(QuadroRelogio, 0, Relogio.Width / 7, Relogio.Height), Color.White);
            spriteBatch.Draw(vida, posicao_vida, Color.White);
            spriteBatch.DrawString(Font, "" + Game1.Vida, new Vector2(890, 20), Color.Black);
            spriteBatch.DrawString(Font, "" + Game1.pontosTotal, new Vector2(745, 20), Color.Black);


            return spriteBatch;
        }
        public SpriteBatch DrawDrawNivelFinal(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(Fundo_HUDFinal, posicao_hud_fundo, Color.White);

            spriteBatch.Draw(TexturaSairFinal, new Rectangle((int)posicao_sair.X, (int)posicao_sair.Y, TexturaSairFinal.Width / 2, TexturaSairFinal.Height), new Rectangle(QuadroSair, 0, TexturaSairFinal.Width / 2, TexturaSairFinal.Height), Color.White);
            spriteBatch.Draw(TexturaSomFinal, new Rectangle((int)posicao_som.X, (int)posicao_som.Y, TexturaSomFinal.Width / 4, TexturaSomFinal.Height), new Rectangle(QuadroSom, 0, TexturaSomFinal.Width / 4, TexturaSomFinal.Height), Color.White);
            spriteBatch.Draw(Placar3Dg, posicao_placar, Color.White);
            spriteBatch.Draw(Relogio, new Rectangle((int)posicao_relogio.X, (int)posicao_relogio.Y, Relogio.Width / 7, Relogio.Height), new Rectangle(QuadroRelogio, 0, Relogio.Width / 7, Relogio.Height), Color.White);
            spriteBatch.Draw(vida, posicao_vida, Color.White);
            spriteBatch.DrawString(Font, "" + Game1.Vida, new Vector2(890, 20), Color.Black);
            spriteBatch.DrawString(Font, "" + Game1.pontosTotal, new Vector2(745, 20), Color.Black);



            return spriteBatch;
        }

        public void ImagemSom(MouseState mouse_atual, MouseState mouse_anterior)
        {
            if (mouse_atual.LeftButton == ButtonState.Pressed && mouse_anterior.LeftButton!= ButtonState.Pressed && mouse_atual.X > posicao_som.X && mouse_atual.X < posicao_som.X + 42 &&
                  mouse_atual.Y > posicao_som.Y && mouse_atual.Y < posicao_som.Y + 36)
            {
                if (Mudo && !SairSelecionado)
                {
                    MediaPlayer.IsMuted = false;
                    SoundEffect.MasterVolume = 1;                    
                    QuadroSom = 0;
                    SomSelecionado = true;
                    Mudo = false;

                }
                else if (!Mudo && !SairSelecionado)
                {
                    MediaPlayer.IsMuted = true;
                    SoundEffect.MasterVolume = 0;
                    QuadroSom = 82;
                    SomSelecionado = true;
                    Mudo = true;

                }
            }
            else if (!(mouse_atual.X > posicao_som.X && mouse_atual.X < posicao_som.X + 42 &&
                  mouse_atual.Y > posicao_som.Y && mouse_atual.Y < posicao_som.Y + 36) && Mudo)
            {
                QuadroSom = 123;
                SomSelecionado = false;
                
            }
            else if (!(mouse_atual.X > posicao_som.X && mouse_atual.X < posicao_som.X + 42 &&
                  mouse_atual.Y > posicao_som.Y && mouse_atual.Y < posicao_som.Y + 36) && !Mudo)
            {
                QuadroSom = 41;
                SomSelecionado = false;
            }
            else if (mouse_atual.X > posicao_som.X && mouse_atual.X < posicao_som.X + 42 &&
                  mouse_atual.Y > posicao_som.Y && mouse_atual.Y < posicao_som.Y + 36 && Mudo && !SairSelecionado)
            {
                QuadroSom = 82;
                SomSelecionado = true;

            }
            else if (mouse_atual.X > posicao_som.X && mouse_atual.X < posicao_som.X + 42 &&
                 mouse_atual.Y > posicao_som.Y && mouse_atual.Y < posicao_som.Y + 36 && !Mudo && !SairSelecionado)
            {
                QuadroSom = 0;
                SomSelecionado = true;

            }
        }
        public void ImagemSair(MouseState mouse)
        {
            if ((mouse.X > posicao_sair.X  && mouse.X < posicao_sair.X + 51 &&
                  mouse.Y > posicao_sair.Y && mouse.Y < posicao_sair.Y + 50)&& !SomSelecionado)
            {
                QuadroSair = 0;
                SairSelecionado = true;

                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    fechar = true;
                }
                
                
            }
            else if (!(mouse.X > posicao_sair.X && mouse.X < posicao_sair.X + 51 &&
                  mouse.Y > posicao_sair.Y && mouse.Y < posicao_sair.Y + 50))
            {
                QuadroSair = 51;
                SairSelecionado = false;

            }
           
        }

        public void Resultado()
        {
            switch (spriteRelogio)
            {
                case 1:
                    {
                        QuadroRelogio = 33;
                        break;
                    }

                case 2:
                    {
                        QuadroRelogio = 66;
                        break;
                    }

                case 3:
                    {
                        QuadroRelogio = 99;
                        break;
                    }

                case 4:
                    {
                       QuadroRelogio = 132;
                        break;
                    }
                case 5:
                    {
                       QuadroRelogio = 165;
                        break;
                    }

                case 6:
                    {
                        QuadroRelogio = 198;
                        break;
                    }

                case 7:
                    {
                        QuadroRelogio = 231;
                        break;
                    }
            }

        }

       

    }


}
